home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 83
/
(Vol 83) My Disc.iso
/
Games
/
hello_kitty.swf
/
scripts
/
frame_16
/
DoAction.as
Wrap
Text File
|
2008-08-07
|
7KB
|
260 lines
function enemyBrain8()
{
var i = 0;
while(i < 10)
{
var name = "enemy" + i;
var ob = game[name];
getMyCorners(ob.x + ob.speed * ob.xMove,ob.y + ob.speed * ob.yMove,ob);
if(ob.downleft and ob.upleft and ob.downright and ob.upleft)
{
moveChar(ob,ob.xMove,ob.yMove);
}
else
{
ob.xMove = - ob.xMove;
ob.yMove = - ob.yMove;
}
if(!_root.infiniteLife)
{
var xdist = ob.x - char.x;
var ydist = ob.y - char.y;
if(math.sqrt(xdist * xdist + ydist * ydist) < ob.width + char.width)
{
_root.lifes -= 1;
youdied.gotoandplay(2);
mylifes.gotoandstop(_root.lifes);
if(_root.lifes == 0)
{
removeMovieClip(_root.tiles);
gotoAndStop(35);
}
if(!_root.hurt)
{
char.clip.gotoAndPlay("hurt");
return undefined;
}
}
}
i++;
}
}
function detectKeys_8()
{
var ob = _root.char;
var keypressed = false;
if(key.isDown(39))
{
keyPressed = _root.moveChar8(ob,1,0);
}
else if(key.isDown(37))
{
keyPressed = _root.moveChar8(ob,-1,0);
}
else if(key.isDown(38))
{
keyPressed = _root.moveChar8(ob,0,-1);
}
else if(key.isDown(40))
{
keyPressed = _root.moveChar8(ob,0,1);
}
if(!KeyPressed)
{
ob.clip.mychar.gotoandstop(1);
}
else
{
ob.clip.mychar.play();
}
enemyBrain8();
}
function moveChar8(ob, dirx, diry)
{
getMyCorners(ob.x,ob.y + ob.speed * diry,ob);
if(diry == -1)
{
if(ob.upleft and ob.upright)
{
ob.y += ob.speed * diry;
}
else
{
ob.y = ob.ytile * game.tileH + ob.height;
}
}
if(diry == 1)
{
if(ob.downleft and ob.downright)
{
ob.y += ob.speed * diry;
}
else
{
ob.y = (ob.ytile + 1) * game.tileH - ob.height;
}
}
getMyCorners(ob.x + ob.speed * dirx,ob.y,ob);
if(dirx == -1)
{
if(ob.downleft and ob.upleft)
{
ob.x += ob.speed * dirx;
}
else
{
ob.x = ob.xtile * game.tileW + ob.width;
}
}
if(dirx == 1)
{
if(ob.upright and ob.downright)
{
ob.x += ob.speed * dirx;
}
else
{
ob.x = (ob.xtile + 1) * game.tileW - ob.width;
}
}
ob.clip._x = ob.x;
ob.clip._y = ob.y;
ob.clip.gotoandstop(dirx + diry * 2 + 3);
ob.xtile = Math.floor(ob.clip._x / game.tileW);
ob.ytile = Math.floor(ob.clip._y / game.tileH);
var itemname = game["item" + ob.ytile + "_" + ob.xtile];
if(itemname and ob == _root.char)
{
game.points += itemname.points;
removeMovieClip(itemname.clip);
game.items[itemname.position] = 0;
delete game["item" + ob.ytile + "_" + ob.xtile];
}
if(game.points == 1)
{
openwallname = "t_1_6";
game.clip[openwallname].gotoandstop(1);
openwallname = "t_3_3";
game.clip[openwallname].gotoandstop(1);
openwallname2 = "t_2_3";
game.clip[openwallname2].gotoandstop(1);
openwallname3 = "t_1_3";
game.clip[openwallname3].gotoandstop(1);
game.Tile7.prototype.walkable = true;
}
if(game.points == 2)
{
opendoorname = "t_" + unlockY + "_" + unlockX;
game.clip[opendoorname].gotoandstop(4);
game.Tile2.prototype.walkable = true;
}
if(_root.char.ytile == unlockY && _root.char.xtile == unlockX)
{
_root.tempLv = 9;
removeMovieClip(_root.tiles);
gotoAndStop(40);
}
if(_root.char.ytile == 7 && _root.char.xtile == 2 || _root.char.ytile == 7 && _root.char.xtile == 3 || _root.char.ytile == 7 && _root.char.xtile == 6 || _root.char.ytile == 1 && _root.char.xtile == 7 || _root.char.ytile == 2 && _root.char.xtile == 4 || _root.char.ytile == 3 && _root.char.xtile == 4 || _root.char.ytile == 3 && _root.char.xtile == 2)
{
_root.char.speed = 0.5;
}
else
{
_root.char.speed = 3;
}
return true;
}
function getMyCorners(x, y, ob)
{
ob.downY = Math.floor((y + ob.height - 1) / game.tileH);
ob.upY = Math.floor((y - ob.height) / game.tileH);
ob.leftX = Math.floor((x - ob.width) / game.tileW);
ob.rightX = Math.floor((x + ob.width - 1) / game.tileW);
ob.upleft = game["t_" + ob.upY + "_" + ob.leftX].walkable;
ob.downleft = game["t_" + ob.downY + "_" + ob.leftX].walkable;
ob.upright = game["t_" + ob.upY + "_" + ob.rightX].walkable;
ob.downright = game["t_" + ob.downY + "_" + ob.rightX].walkable;
}
removeMovieClip(_root.tiles);
getURL("FSCommand:allowscale",true);
myMap1 = [[1,1,1,1,1,1,1,1,1,1],[1,0,0,7,0,0,7,6,0,1],[1,0,0,7,6,0,0,1,0,1],[1,0,6,7,6,0,0,0,1,1],[1,2,0,1,0,0,0,0,0,1],[1,1,1,1,1,1,0,0,0,1],[1,0,1,1,0,1,0,0,1,1],[1,0,6,6,0,0,6,1,1,1],[1,1,1,1,1,1,1,1,1,1]];
game = {tileW:45,tileH:45,currentMap:1,points:0,wallkey:false};
game.Tile0 = function()
{
};
game.Tile0.prototype.walkable = true;
game.Tile0.prototype.frame = 1;
game.Tile1 = function()
{
};
game.Tile1.prototype.walkable = false;
game.Tile1.prototype.frame = 2;
game.Tile2 = function()
{
};
game.Tile2.prototype.walkable = false;
game.Tile2.prototype.frame = 3;
game.Tile5 = function()
{
};
game.Tile5.prototype.walkable = false;
game.Tile5.prototype.frame = 5;
game.Tile6 = function()
{
};
game.Tile6.prototype.walkable = true;
game.Tile6.prototype.frame = 6;
game.Tile7 = function()
{
};
game.Tile7.prototype.walkable = false;
game.Tile7.prototype.frame = 2;
unlockY = 4;
unlockX = 1;
char = {xtile:1,ytile:6,speed:3};
startingXtile = char.xtile;
startingYtile = char.ytile;
mylifes.gotoandstop(_root.lifes);
myEnemies = [[2,1,2],[2,2,1],[5,1,1],[3,2,2],[3,1,3],[3,6,7],[3,7,4],[2,6,2],[2,5,2],[2,7,4]];
game.Enemyp1 = function()
{
};
game.Enemyp1.prototype.xMove = 0;
game.Enemyp1.prototype.yMove = 1;
game.Enemyp1.prototype.speed = 2;
game.Enemyp2 = function()
{
};
game.Enemyp2.prototype.xMove = 0;
game.Enemyp2.prototype.yMove = 1;
game.Enemyp2.prototype.speed = 0.5;
game.Enemyp3 = function()
{
};
game.Enemyp3.prototype.xMove = 1;
game.Enemyp3.prototype.yMove = 0;
game.Enemyp3.prototype.speed = 1;
game.Enemyp4 = function()
{
};
game.Enemyp4.prototype.xMove = 0;
game.Enemyp4.prototype.yMove = 1;
game.Enemyp4.prototype.speed = 1.5;
game.Enemyp5 = function()
{
};
game.Enemyp5.prototype.xMove = 1;
game.Enemyp5.prototype.yMove = 0;
game.Enemyp5.prototype.speed = 0.5;
myItems = [[1,8,1],[2,6,3]];
game.Item1 = function()
{
};
game.Item1.prototype.points = 1;
game.Item2 = function()
{
};
game.Item2.prototype.points = 1;
_root.buildMap(_root["myMap" + game.currentMap]);
stop();